#include<bits/stdc++.h>
using namespace std;
int t,n,a[200005],u[200005],ans;
void p(int dep){
    if (dep>n){
        int sum=0;
        for (int i=1;i<=n;i++){
            int j=i-1;
            while (u[j]!=u[i]&&j>0) j--;
            if (j>0&&a[i]==a[j]) sum+=a[i];
        }
        ans=max(ans,sum);
        return ;
    }
    u[dep]=0;
    p(dep+1);
    u[dep]=1;
    p(dep+1);
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%d",&t);
    while (t--){
        scanf("%d",&n);ans=0;
        for (int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        p(1);
        cout<<ans<<endl;
    }
    return 0;
}
